import { makeObservable, action, observable } from 'mobx'
import axios from 'axios'

export default class QmusicStore {
  constructor () {
    makeObservable(this, {
      qlist: observable,
      getQList: action
    })
  }

  // 创建QQ音乐的列表的数组
  qlist = []

  // action请求数据，发起axios数据请求
  getQList (payload) {
    let str =  `ct=24&qqmusic_ver=1298&new_json=1&remoteplace=txt.yqq.top&searchid=25697592547780876&t=0&aggr=1&cr=1&catZhida=1&lossless=0&flag_qc=0&p=${payload.p}&n=10&w=${payload.w}&g_tk_new_20200303=264588153&g_tk=264588153&loginUin=1691732926&hostUin=0&format=json&inCharset=utf8&outCharset=utf-8&notice=0&platform=yqq.json&needNewCode=0`

    str.split('&').map(item => {
      const arr = item.split('=')
      payload[arr[0]] = arr[1]
    })

    axios.get('http://localhost:8080/soso/fcgi-bin/client_search_cp', {
      params: payload
    }).then(res => {
      this.qlist = res.data.data.song.list
    })
  }
}